home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / disk.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  38KB  |  1,551 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATUtilities Disk Transfer                 ** */
  4. /* **            Copright (C) 1992-1993 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include <devices/trackdisk.h>
  10. #include "janus.h"
  11. #include "ATUtilities.h"
  12.  
  13. #define REGISTER_NOPROGS
  14. #include "register.h"
  15.  
  16. #define BIT15 (1<<15)
  17.  
  18. struct UDevice
  19. {
  20.  UBYTE              Name[100];
  21.  UWORD              Unit;
  22.  ULONG              Heads;
  23.  ULONG              SectorsPerTrack;
  24.  ULONG              Tracks;
  25.  UWORD              Motor;
  26.  BOOL               File;
  27. };
  28.  
  29. struct CacheBlock
  30. {
  31.  ULONG  Changes;
  32.  ULONG  Offset;
  33.  UWORD  Length;
  34.  UBYTE *Memory;
  35.  UBYTE *NextCacheBlock;
  36. };
  37.  
  38. struct TDevice
  39. {
  40.  BOOL               Valid;
  41.  ULONG              Changes;
  42.  struct FileHandle *FileHandle;
  43.  struct IOStdReq   *Request;
  44.  struct MsgPort    *Port;
  45.  LONG               Device;
  46.  struct CacheBlock *FirstCacheBlock;
  47.  struct Remember   *CacheRemember;
  48. };
  49.  
  50. struct UDevice ud[6]=
  51. {
  52.  "trackdisk.device",0,2,11,80,4,FALSE,
  53.  "trackdisk.device",1,2,11,80,4,FALSE,
  54.  "trackdisk.device",0,1,11,80,4,FALSE,
  55.  "trackdisk.device",1,1,11,80,4,FALSE,
  56.  "DH0:Trashcan/File01",0,2,11,80,0,TRUE,
  57.  "DH0:Trashcan/File02",0,4,16,200,0,TRUE
  58. };
  59.  
  60. struct TDevice td[6]=
  61. {
  62.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  63.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  64.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  65.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  66.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  67.  TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
  68. };
  69.  
  70. UWORD Active;
  71. UWORD MotorCNT[6]={0,0,0,0,0,0};
  72.  
  73. UBYTE *TransferPort="ATUtilities Disk Transfer";
  74. UBYTE *PrefsName="AT:Prefs/DiskTransfer.prefs";
  75. UBYTE *HelpName="AT:Help/DiskTransfer.help";
  76.  
  77. LONG  JanusSignal;
  78. LONG  PortSignal;
  79. LONG  TaskSignal;
  80. ULONG JanusSignalMask;
  81. ULONG PortSignalMask;
  82. ULONG WaitSignalMask;
  83. ULONG TaskSignalMask;
  84. ULONG AppSignalMask;
  85. ULONG Signale;
  86.  
  87. struct JanusBase *JanusBase;
  88. struct Library   *GfxBase;
  89. struct Library   *IntuitionBase;
  90. struct Library   *ATUtilitiesBase;
  91.  
  92. struct Process      *MotorTask;
  93. struct Task         *MainTask;
  94. struct MsgPort      *TaskPort,*ReplyPort;
  95. struct ExtSetupSig  *ExtSetupSig;
  96. struct Window       *WindowPtr;
  97. struct RastPort     *rp;
  98. struct CommMemory   *jhbyte,*jhword;
  99. struct AppManager   *app;
  100. struct Message       Message;
  101. struct Message      *AppMessage;
  102.  
  103. #ifdef SHAREWARE
  104. VOID RegCheck();
  105. #endif
  106. VOID HandleInt();
  107. VOID WriteCache();
  108. VOID ShowInfo();
  109. VOID Motor();
  110. VOID EditiereLW();
  111. VOID ZeigeLW();
  112. BOOL EinstellungenAendern();
  113. BOOL AddCache();
  114. VOID InstallAll();
  115. VOID UninstallAll();
  116. VOID InstallFile();
  117. VOID UninstallFile();
  118. VOID InstallDevice();
  119. VOID UninstallDevice();
  120. VOID OpenAll();
  121. VOID CloseAll();
  122. VOID Bearbeite();
  123. VOID BearbeiteFile();
  124. WORD ChangeCheck();
  125. VOID CalcFAT();
  126. VOID MotorOnOff();
  127. VOID Format();
  128. VOID Kopiere();
  129.  
  130. UBYTE           *mem;
  131. struct MsgPort  *Port;
  132.  
  133.  
  134. /* Installationsroutine */
  135. VOID main()
  136. {
  137.  REGISTER UWORD i;
  138.  REGISTER BOOL  bool;
  139.  
  140.  OpenAll();
  141.  bool=FALSE;
  142.  while(bool==FALSE)
  143.   {
  144.    Signale=Wait(WaitSignalMask);
  145.    if(Signale & PortSignalMask)
  146.     {
  147.      i=Received(Port);
  148.      switch(i)
  149.       {
  150.        case UTILITY_CALL:
  151.          bool=EinstellungenAendern();
  152.         break;
  153.        case UTILITY_QUIT:
  154.          bool=ExitWarning();
  155.         break;
  156.        case UTILITY_INFO:
  157.          ShowInfo();
  158.         break;
  159.        case UTILITY_HELP:
  160.          Help(HelpName,0);
  161.         break;
  162.       }
  163.     }
  164.    if(Signale & JanusSignalMask)
  165.     {
  166.      HandleInt();
  167.     }
  168.    if(Signale & TaskSignalMask)
  169.     {
  170.      for(i=0;i<6;i++)
  171.       {
  172.        if(MotorCNT[i]>0)
  173.         {
  174.          MotorCNT[i]--;
  175.          if(MotorCNT[i]==0)
  176.           {
  177.            WriteCache(i);
  178.            MotorOnOff(i,0);
  179.           }
  180.         }
  181.       }
  182.     }
  183.    if(app!=NULL)
  184.     {
  185.      if(Signale & AppSignalMask)
  186.       {
  187.        AppMessage=GetMsg(app->Port);
  188.        if(AppMessage!=NULL)
  189.         {
  190.          ReplyMsg(AppMessage);
  191.          bool=EinstellungenAendern();
  192.         }
  193.       }
  194.     }
  195.   }
  196.  CloseAll();
  197. }
  198.  
  199.  
  200. /* PC-Befehle ausführen */
  201. VOID HandleInt()
  202. {
  203.  REGISTER BOOL  bool;
  204.  REGISTER UWORD i,l;
  205.  REGISTER ULONG o;
  206.  
  207.  switch(jhword->Arg1)
  208.   {
  209.    case 1:
  210.      if(ud[Active].File==FALSE)
  211.       {
  212.        l=jhword->Arg2*512;
  213.        o=jhword->Arg3*512;
  214.        bool=AddCache(&jhword->Memory,o,l);
  215.        if(bool==FALSE)
  216.         {
  217.          WriteCache(Active);
  218.          MotorCNT[Active]=ud[Active].Motor;
  219.          td[Active].Request->io_Data=mem;
  220.          CopyMemQuick(&jhword->Memory,mem,l);
  221.          td[Active].Request->io_Data=mem;
  222.          td[Active].Request->io_Length=l;
  223.          td[Active].Request->io_Offset=o;
  224.          td[Active].Request->io_Command=CMD_WRITE;
  225.          i=DoIO(td[Active].Request);
  226.          if(i!=0)
  227.           {
  228.            switch(i)
  229.             {
  230.              case 28:
  231.                jhword->Arg2=0+BIT15;
  232.               break;
  233.              case 29:
  234.                jhword->Arg2=15+BIT15;
  235.               break;
  236.              default:
  237.                jhword->Arg2=10+BIT15;
  238.               break;
  239.             }
  240.           }
  241.          else
  242.           {
  243.            jhword->Arg2=0;
  244.           }
  245.          td[Active].Request->io_Command=CMD_UPDATE;
  246.          i=DoIO(td[Active].Request);
  247.          if(i!=0)
  248.           {
  249.            switch(i)
  250.             {
  251.              case 28:
  252.                jhword->Arg2=0+BIT15;
  253.               break;
  254.              case 29:
  255.                jhword->Arg2=15+BIT15;
  256.               break;
  257.              default:
  258.                jhword->Arg2=10+BIT15;
  259.               break;
  260.             }
  261.           }
  262.          else
  263.           {
  264.            jhword->Arg2=0;
  265.           }
  266.         }
  267.       }
  268.      else
  269.       {
  270.        l=jhword->Arg2*512;
  271.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  272.        i=Write(td[Active].FileHandle,&jhword->Memory,l);
  273.        if(i==l)
  274.         {
  275.          jhword->Arg2=0;
  276.         }
  277.        else
  278.         {
  279.          jhword->Arg2=10+BIT15;
  280.         }
  281.       }
  282.     break;
  283.    case 2:
  284.      if(ud[Active].File==FALSE)
  285.       {
  286.        WriteCache(Active);
  287.        MotorCNT[Active]=ud[Active].Motor;
  288.        td[Active].Request->io_Data=mem;
  289.        l=jhword->Arg2*512;
  290.        td[Active].Request->io_Length=l;
  291.        td[Active].Request->io_Offset=jhword->Arg3*512;
  292.        td[Active].Request->io_Command=CMD_READ;
  293.        i=DoIO(td[Active].Request);
  294.        if(i!=0)
  295.         {
  296.          switch(i)
  297.           {
  298.            case 29:
  299.              jhword->Arg2=15+BIT15;
  300.             break;
  301.            default:
  302.              jhword->Arg2=11+BIT15;
  303.             break;
  304.           }
  305.         }
  306.        else
  307.         {
  308.          CopyMemQuick(mem,&jhword->Memory,l);
  309.          jhword->Arg2=0;
  310.         }
  311.       }
  312.      else
  313.       {
  314.        l=jhword->Arg2*512;
  315.        Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
  316.        i=Read(td[Active].FileHandle,&jhword->Memory,l);
  317.        if(i==l)
  318.         {
  319.          jhword->Arg2=0;
  320.         }
  321.        else
  322.         {
  323.          jhword->Arg2=15+BIT15;
  324.         }
  325.       }
  326.     break;
  327.    case 3:
  328.      jhword->Arg2=0;
  329.     break;
  330.    case 4:
  331.      if(ud[Active].File==FALSE)
  332.       {
  333.        jhword->Arg2=ChangeCheck(Active);
  334.       }
  335.      else
  336.       {
  337.        jhword->Arg2=1;
  338.       }
  339.     break;
  340.    case 5:
  341.      jhword->Arg2=ud[Active].Tracks*ud[Active].Heads*ud[Active].SectorsPerTrack;
  342.      jhword->Arg3=ud[Active].Tracks;
  343.      jhword->Arg4=ud[Active].Heads;
  344.      CalcFAT(Active);
  345.      if(ud[Active].File==FALSE) jhword->Arg7=0; else jhword->Arg7=1;
  346.     break;
  347.    case 6:
  348.      for(i=0;i<6;i++)
  349.       {
  350.        MotorOnOff(i,1);
  351.        MotorCNT[i]=ud[Active].Motor;
  352.       }
  353.     break;
  354.    case 10:
  355.      Format();
  356.     break;
  357.    case 20:
  358.      Kopiere();
  359.     break;
  360.    case 100:
  361.      if(td[jhword->Arg2].Valid==FALSE)
  362.       {
  363.        jhword->Arg2=2+BIT15;
  364.       }
  365.      else
  366.       {
  367.        Active=jhword->Arg2;
  368.        jhword->Arg2=0;
  369.       }
  370.     break;
  371.    default:
  372.     break;
  373.   }
  374.  SendJanusInt(29);
  375. }
  376.  
  377.  
  378. /* Diskettenwechsel prüfen */
  379. WORD ChangeCheck(num)
  380.  UWORD num;
  381. {
  382.  REGISTER LONG i;
  383.  
  384.  td[num].Request->io_Command=TD_CHANGENUM;
  385.  DoIO(td[num].Request);
  386.  i=td[num].Request->io_Actual;
  387.  if(i!=td[num].Changes)
  388.   {
  389.    td[num].Changes=i;
  390.    return(0xFF);
  391.   }
  392.  return(1);
  393. }
  394.  
  395.  
  396. /* Laufwerke öffnen */
  397. VOID InstallAll()
  398. {
  399.  REGISTER LONG i;
  400.  
  401.  for(i=0;i<6;i++)
  402.   {
  403.    if(ud[i].File==FALSE)
  404.     {
  405.      InstallDevice(i);
  406.     }
  407.    else
  408.     {
  409.      InstallFile(i);
  410.     }
  411.   }
  412. }
  413.  
  414.  
  415. /* Laufwerke schließen */
  416. VOID UninstallAll()
  417. {
  418.  REGISTER LONG i;
  419.  
  420.  for(i=0;i<6;i++)
  421.   {
  422.    if(ud[i].File==FALSE)
  423.     {
  424.      UninstallDevice(i);
  425.     }
  426.    else
  427.     {
  428.      UninstallFile(i);
  429.     }
  430.   }
  431. }
  432.  
  433.  
  434. VOID InstallDevice(num)
  435.  UWORD num;
  436. {
  437.  
  438.  td[num].Port=CreatePort(0L,0L);
  439.  if(td[num].Port!=NULL)
  440.   {
  441.    td[num].Request=CreateExtIO(td[num].Port,200);
  442.    if(td[num].Request!=NULL)
  443.     {
  444.      td[num].Device=OpenDevice(&ud[num].Name,ud[num].Unit,td[num].Request,0);
  445.      if(td[num].Device!=0)
  446.       {
  447.        UninstallDevice(num);
  448.       }
  449.     }
  450.    else
  451.     {
  452.      UninstallDevice(num);
  453.     }
  454.   }
  455.  else
  456.   {
  457.    UninstallDevice(num);
  458.   }
  459. }
  460.  
  461.  
  462. VOID UninstallDevice(num)
  463.  UWORD num;
  464. {
  465.  
  466.  if(td[num].Valid==TRUE)
  467.   {
  468.    if(td[num].Device==0L) CloseDevice(td[num].Request);
  469.    if(td[num].Request) DeleteExtIO(td[num].Request);
  470.    if(td[num].Port) DeletePort(td[num].Port);
  471.    td[num].Valid=FALSE;
  472.   }
  473. }
  474.  
  475.  
  476. /* Datei installieren */
  477. VOID InstallFile(num)
  478.  UWORD num;
  479. {
  480.  REGISTER ULONG            i,j;
  481.  register struct FileLock *lock;
  482.  
  483.  td[num].Valid=FALSE;
  484.  lock=Lock(&ud[num].Name,ACCESS_READ);
  485.  if(lock!=NULL)
  486.   {
  487.    UnLock(lock);
  488.    td[num].FileHandle=Open(&ud[num].Name,MODE_READWRITE);
  489.    if(td[num].FileHandle!=NULL)
  490.     {
  491.      Seek(td[num].FileHandle,0,OFFSET_END);
  492.      i=Seek(td[num].FileHandle,0,OFFSET_BEGINNING);
  493.      j=512L*(ULONG)ud[num].Tracks*(ULONG)ud[num].Heads*(ULONG)ud[num].SectorsPerTrack;
  494.      if(i!=j)
  495.       {
  496.        MultiRequest("Inkompatible Dateilänge bei LW-Datei",&ud[num].Name,"Okay",NULL);
  497.        Close(td[num].FileHandle);
  498.       }
  499.      else
  500.       {
  501.        td[num].Valid=TRUE;
  502.       }
  503.     }
  504.   }
  505. }
  506.  
  507.  
  508. VOID UninstallFile(num)
  509.  UWORD num;
  510. {
  511.  
  512.  if(td[num].Valid==TRUE)
  513.   {
  514.    if(td[num].FileHandle) Close(td[num].FileHandle);
  515.    td[num].Valid=FALSE;
  516.   }
  517. }
  518.  
  519.  
  520. /* Installationsroutine */
  521. VOID OpenAll()
  522. {
  523.  REGISTER UWORD              i;
  524.  register struct MsgPort    *p;
  525.  register struct FileHandle *fh;
  526.  
  527.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  528.  if(ATUtilitiesBase==NULL)
  529.   {
  530.    printf("Kann ATUtilities-Library nicht öffnen.\n");
  531.    CloseAll();
  532.   }
  533.  
  534.  GfxBase=OpenLibrary("graphics.library",0L);
  535.  IntuitionBase=OpenLibrary("intuition.library",0L);
  536.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  537.   {
  538.    CloseAll();
  539.   }
  540.  
  541.  p=FindPort(TransferPort);
  542.  if(p!=NULL)
  543.   {
  544.    InfoRequest("ATUtilities Disk Transfer ist schon aktiv.");
  545.    CloseAll();
  546.   }
  547.  
  548.  MainTask=FindTask(NULL);
  549.  SetTaskPri(MainTask,10);
  550.  
  551.  JanusBase=OpenLibrary("janus.library",0L);
  552.  if(JanusBase==NULL)
  553.   {
  554.    ErrorRequest(ERROR_JANUS);
  555.    CloseAll();
  556.   }
  557.  
  558.  TaskSignal=AllocSignal(-1L);
  559.  if(TaskSignal==-1L)
  560.   {
  561.    ErrorRequest(ERROR_SIGNAL);
  562.    CloseAll();
  563.   }
  564.  
  565.  Port=CreatePort(TransferPort,0L);
  566.  if(Port==NULL)
  567.   {
  568.    ErrorRequest(ERROR_MPORT);
  569.    CloseAll();
  570.   }
  571.  
  572.  fh=Open(PrefsName,MODE_OLDFILE);
  573.  if(fh!=NULL)
  574.   {
  575.    Read(fh,&ud,sizeof(struct UDevice)*6);
  576.    Close(fh);
  577.   }
  578.  
  579.  InstallAll();
  580.  
  581.  mem=AllocMem(PUBLIC_PAGESIZE,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  582.  if(mem==NULL)
  583.   {
  584.    ErrorRequest(ERROR_ALLOC);
  585.    CloseAll();
  586.   }
  587.  
  588.  ExtSetupSig=CreatePublicHandler(29);
  589.  if(ExtSetupSig==NULL)
  590.   {
  591.    CloseAll();
  592.   }
  593.  
  594.  TaskPort=CreatePort("Disk Transfer Motor Task <Stop>",0L);
  595.  ReplyPort=CreatePort("Disk Transfer <Stop> Reply",0L);
  596.  if((TaskPort==NULL)||(ReplyPort==NULL))
  597.   {
  598.    ErrorRequest(ERROR_PORT);
  599.    CloseAll();
  600.   }
  601.  
  602.  MotorTask=CreateProcess(Motor,500,"Disk Transfer Motor Task",2);
  603.  if(MotorTask==NULL)
  604.   {
  605.    DeletePort(TaskPort);
  606.    InfoRequest("Kann Motor-Task nicht erstellen.\n");
  607.    CloseAll();
  608.   }
  609.  
  610.  app=CreateAppItem("ATUtilities Disk Transfer");
  611.  if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
  612.  
  613.  jhword=ExtSetupSig->WordAccess;
  614.  jhbyte=ExtSetupSig->ByteAccess;
  615.  PortSignal=Port->mp_SigBit;
  616.  PortSignalMask=(1L<<PortSignal);
  617.  JanusSignal=ExtSetupSig->JanusSignal;
  618.  JanusSignalMask=ExtSetupSig->JanusSignalMask;
  619.  TaskSignalMask=(1L<<TaskSignal);
  620.  WaitSignalMask=PortSignalMask+JanusSignalMask+TaskSignalMask+AppSignalMask;
  621. }
  622.  
  623.  
  624. /* Programmende */
  625. VOID CloseAll()
  626. {
  627.  if(app) DeleteAppItem(app);
  628.  if(MotorTask!=NULL)
  629.   {
  630.    Message.mn_Node.ln_Type=NT_MESSAGE;
  631.    Message.mn_ReplyPort=ReplyPort;
  632.    PutMsg(TaskPort,&Message);
  633.    WaitPort(ReplyPort);
  634.    DeletePort(ReplyPort);
  635.   }
  636.  if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
  637.  if(mem) FreeMem(mem,PUBLIC_PAGESIZE);
  638.  if(TaskSignal!=-1) FreeSignal(TaskSignal);
  639.  if(Port) DeletePort(Port);
  640.  UninstallAll();
  641.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  642.  if(GfxBase) CloseLibrary(GfxBase);
  643.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  644.  if(JanusBase) CloseLibrary(JanusBase);
  645.  exit(0);
  646. }
  647.  
  648.  
  649. /* Einstellungs-Fenster */
  650. BOOL EinstellungenAendern()
  651. {
  652.  UBYTE                        text[40];
  653.  BOOL                         bool,ende;
  654.  REGISTER ULONG               Class;
  655.  REGISTER WORD                i,j,id;
  656.  register struct Window       *win;
  657.  register struct RastPort     *rp;
  658.  register struct Gadget       *gad;
  659.  register struct IntuiMessage *msg;
  660.  register struct TextFont     *opal;
  661.  
  662. #ifdef SHAREWARE
  663.  RegCheck();
  664. #endif
  665.  win=CreateStdWindow("ATUtilities - Disk Transfer Einstellungen",
  666.                      75,75,450,122,CLOSEWINDOW|GADGETUP,
  667.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  668.  ende=FALSE;
  669.  if(win!=NULL)
  670.   {
  671.    rp=win->RPort;
  672.    opal=GetOpalFont();
  673.    SetFont(rp,opal);
  674.  
  675.    CreateBoolGadget(win,10,15,155,12,"Einstellungen Okay",1);
  676.    CreateBoolGadget(win,170,15,155,12,"Programm beenden",2);
  677.    CreateBoolGadget(win,335,15,50,12,"Info",3);
  678.    CreateBoolGadget(win,390,15,50,12,"Hilfe",4);
  679.    for(i=0,j=10;i<6;i++,j++)
  680.     {
  681.      sprintf(&text,"Laufwerk %ld:",i+1);
  682.      CreateBoolGadget(win,33,35+(i*14),120,12,&text,j);
  683.      CreateBoolGadget(win,10,35+(i*14),20,12,"!",i+100);
  684.      ZeigeLW(rp,i);
  685.     }
  686.  
  687.    bool=FALSE;
  688.    while(bool==FALSE)
  689.     {
  690.      WaitPort(win->UserPort);
  691.      msg=GetMsg(win->UserPort);
  692.      Class=msg->Class;
  693.      gad=msg->IAddress;
  694.      ReplyMsg(msg);
  695.      switch(Class)
  696.       {
  697.        case GADGETUP:
  698.          id=gad->GadgetID;
  699.          switch(id)
  700.           {
  701.            case 1:
  702.              bool=TRUE;
  703.             break;
  704.            case 2:
  705.              ende=TRUE; bool=TRUE;
  706.             break;
  707.            case 3:
  708.              ShowInfo();
  709.             break;
  710.            case 4:
  711.              Help(HelpName,0);
  712.             break;
  713.            default:
  714.              if((id>=10)&&(id<=15))
  715.               {
  716.                j=id-10;
  717.                EditiereLW(j);
  718.                ZeigeLW(rp,j);
  719.               }
  720.              if((id>=100)&&(id<=105))
  721.               {
  722.                j=id-100;
  723.                if(ud[j].File==FALSE)
  724.                 {
  725.                  if(td[j].Valid==TRUE)
  726.                   {
  727.                    Bearbeite(j);
  728.                   }
  729.                  else
  730.                   {
  731.                    MultiRequest("Dieses Device ist nocht nicht verfügbar.",
  732.                                 "Bitte prüfen Sie die Einstellungen.","Okay",0L);
  733.                   }
  734.                 }
  735.                else
  736.                 {
  737.                  BearbeiteFile(j);
  738.                 }
  739.               }
  740.             break;
  741.           }
  742.         break;
  743.        case CLOSEWINDOW:
  744.          bool=TRUE;
  745.         break;
  746.       }
  747.     }
  748.  
  749.    DeleteStdWindow(win);
  750.   }
  751.  if(ende) ende=ExitWarning();
  752.  return(ende);
  753. }
  754.  
  755.  
  756. /* Parameter ändern */
  757. VOID EditiereLW(num)
  758.  UWORD num;
  759. {
  760.  UBYTE                         text[10];
  761.  BOOL                          ende,f;
  762.  ULONG                         a,b,c,d;
  763.  REGISTER ULONG                Class;
  764.  REGISTER WORD                 i,j,id;
  765.  UBYTE                        *bDevice,
  766.                               *bUnit,
  767.                               *bBlocksPerTrack,
  768.                               *bTracks,
  769.                               *bHeads,
  770.                               *bMotor;
  771.  register struct Window       *win;
  772.  register struct RastPort     *rp;
  773.  register struct IntuiMessage *msg;
  774.  register struct TextFont     *opal;
  775.  register struct Gadget       *gad,*isFile;
  776.  struct FileHandle            *fh;
  777.  
  778.  win=CreateStdWindow("Laufwerksparameter editieren",
  779.                      225,90,400,100,CLOSEWINDOW|GADGETUP,
  780.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  781.  ende=FALSE;
  782.  if(win!=NULL)
  783.   {
  784.    rp=win->RPort;
  785.    opal=GetOpalFont();
  786.    SetFont(rp,opal);
  787.  
  788.    CreateBoolGadget(win,10,15,100,12,"Okay",1);
  789.    CreateBoolGadget(win,120,15,100,12,"Abbruch",2);
  790.  
  791.    if(ud[num].File==FALSE)
  792.     {
  793.      isFile=CreateNToggleGadget(win,300,15,80,12,"Als Datei",100);
  794.     }
  795.    else
  796.     {
  797.      isFile=CreateSToggleGadget(win,300,15,80,12,"Als Datei",100);
  798.     }
  799.  
  800.    bDevice=CreateStringGadget(win,120,30,260,10,&ud[num].Name,100,3);
  801.    sprintf(&text,"%ld",ud[num].Unit);
  802.    bUnit=CreateIntegerGadget(win,120,45,60,10,&text,4,4);
  803.    sprintf(&text,"%ld",ud[num].Heads);
  804.    bHeads=CreateIntegerGadget(win,320,45,60,10,&text,5,5);
  805.    sprintf(&text,"%ld",ud[num].Tracks);
  806.    bTracks=CreateIntegerGadget(win,120,57,60,10,&text,7,6);
  807.    sprintf(&text,"%ld",ud[num].SectorsPerTrack);
  808.    bBlocksPerTrack=CreateIntegerGadget(win,320,57,60,10,&text,5,7);
  809.    sprintf(&text,"%ld",ud[num].Motor);
  810.    bMotor=CreateIntegerGadget(win,320,74,60,10,&text,5,8);
  811.  
  812.    WriteText(rp,15,37,"Device/Datei:");
  813.    WriteText(rp,15,52,"Unit:");
  814.    WriteText(rp,220,52,"S/L-Köpfe:");
  815.    WriteText(rp,15,64,"Spuren:");
  816.    WriteText(rp,220,64,"Sekt./Spur:");
  817.    WriteText(rp,15,82,"Motor-Ausschaltzeit nach x Sekunden:");
  818.  
  819.    ende=FALSE;
  820.    while(ende==FALSE)
  821.     {
  822.      WaitPort(win->UserPort);
  823.      msg=GetMsg(win->UserPort);
  824.      Class=msg->Class;
  825.      gad=msg->IAddress;
  826.      ReplyMsg(msg);
  827.      switch(Class)
  828.       {
  829.        case GADGETUP:
  830.          id=gad->GadgetID;
  831.          switch(id)
  832.           {
  833.            case 2:
  834.              ende=TRUE;
  835.             break;
  836.            case 1:
  837.              j=0;
  838.              a=atol(bUnit);
  839.              b=atol(bTracks);
  840.              c=atol(bHeads);
  841.              d=atol(bBlocksPerTrack);
  842.              i=atol(bMotor);
  843.              if(isFile->Flags & SELECTED) f=TRUE; else f=FALSE;
  844.              if(b<2)
  845.               { InfoRequest("Unzulässige Spurenanzahl."); j=1; }
  846.              if(c<1)
  847.               { InfoRequest("Unzulässige S/L-Kopfanzahl."); j++; }
  848.              if(d<2)
  849.               { InfoRequest("Unzulässige Anzahl von Sektoren/Spur."); j++; }
  850.              if(i>180)
  851.               { InfoRequest("Motor-Zeit nicht empfehlenswert (>180s)."); }
  852.              if(j==0)
  853.               {
  854.                if(strcmp(&ud[num].Name,bDevice)) j=1;
  855.                if(ud[num].Unit!=a) j=1;
  856.                if(ud[num].Tracks!=b) j=1;
  857.                if(ud[num].Heads!=c) j=1;
  858.                if(ud[num].SectorsPerTrack!=d) j=1;
  859.                strcpy(&ud[num].Name,bDevice);
  860.                ud[num].Motor=i;
  861.                ud[num].Unit=a;
  862.                ud[num].Tracks=b;
  863.                ud[num].Heads=c;
  864.                ud[num].SectorsPerTrack=d;
  865.                ud[num].File=f;
  866.                if(j==1)
  867.                 {
  868.                  td[num].Valid=FALSE;
  869.                  MultiRequest("Um Probleme mit MS-DOS zu vermeiden, wird",
  870.                               "das Laufwerk erst nach einem Reset aktiv.",
  871.                               "Okay",NULL);
  872.                 }
  873.                fh=Open(PrefsName,MODE_NEWFILE);
  874.                if(fh!=NULL)
  875.                 {
  876.                  Write(fh,&ud,sizeof(struct UDevice)*6);
  877.                  Close(fh);
  878.                 }
  879.                else
  880.                 {
  881.                  InfoRequest("Fehler beim Schreiben der Prefs-Datei.");
  882.                 }
  883.                ende=TRUE;
  884.               }
  885.             break;
  886.           }
  887.         break;
  888.        case CLOSEWINDOW:
  889.          ende=TRUE;
  890.         break;
  891.       }
  892.     }
  893.    DeleteStdWindow(win);
  894.   }
  895. }
  896.  
  897.  
  898. /* Parameter anzeigen */
  899. VOID ZeigeLW(rp,id)
  900.  struct RastPort *rp;
  901.  UWORD            id;
  902. {
  903.  UBYTE          size[20];
  904.  UBYTE          text[30];
  905.  REGISTER ULONG kb;
  906.  
  907.  kb=(ud[id].Heads*ud[id].Tracks*ud[id].SectorsPerTrack*512)/1024;
  908.  if(kb>=10000)
  909.   {
  910.    sprintf(&size,"%ld MB",kb/1024);
  911.   }
  912.  else
  913.   {
  914.    sprintf(&size,"%ld KB",kb);
  915.   }
  916.  if(ud[id].File==FALSE)
  917.   {
  918.    sprintf(&text,"%s  %s  Unit %ld",
  919.                   &size,&ud[id].Name,ud[id].Unit);
  920.   }
  921.  else
  922.   {
  923.    sprintf(&text,"%s  %s",&size,&ud[id].Name);
  924.   }
  925.  WriteText(rp,160,43+(id*14),&text);
  926. }
  927.  
  928.  
  929. /* Device-Laufwerk bearbeiten */
  930. VOID Bearbeite(num)
  931.  UWORD num;
  932. {
  933.  UBYTE                         text[40];
  934.  REGISTER BOOL                 ende,bool;
  935.  REGISTER ULONG                Class;
  936.  REGISTER WORD                 i,j,id;
  937.  register struct Window       *win;
  938.  register struct RastPort     *rp;
  939.  register struct Gadget       *gad;
  940.  register struct IntuiMessage *msg;
  941.  register struct TextFont     *opal;
  942.  register struct Gadget       *verify;
  943.  BOOL                          v;
  944.  ULONG                         BytesPerTrack;
  945.  ULONG                         Track;
  946.  UBYTE                        *FormatMemory;
  947.  
  948.  win=CreateStdWindow("Speichermedium bearbeiten",
  949.                      225,90,300,76,CLOSEWINDOW|GADGETUP,
  950.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  951.  ende=FALSE;
  952.  if(win!=NULL)
  953.   {
  954.    rp=win->RPort;
  955.    opal=GetOpalFont();
  956.    SetFont(rp,opal);
  957.  
  958.    CreateBoolGadget(win,10,12,100,12,"Okay",1);
  959.    CreateBoolGadget(win,10,30,119,12,"Hard-Format",2);
  960.    CreateBoolGadget(win,10,44,172,12,"Prüfe auf Fehler",3);
  961.    verify=CreateSToggleGadget(win,132,30,50,12,"Verify",100);
  962.    DrawNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  963.    DrawNTextBorder(win,190,30,100,12,"0");
  964.    DrawNTextBorder(win,190,44,100,12,"0 %");
  965.  
  966.    ende=FALSE;
  967.    while(ende==FALSE)
  968.     {
  969.      WaitPort(win->UserPort);
  970.      msg=GetMsg(win->UserPort);
  971.      Class=msg->Class;
  972.      gad=msg->IAddress;
  973.      ReplyMsg(msg);
  974.      switch(Class)
  975.       {
  976.        case GADGETUP:
  977.          id=gad->GadgetID;
  978.          switch(id)
  979.           {
  980.            case 2:
  981.            case 3:
  982.              DrawCNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
  983.              if(verify->Flags & SELECTED) v=TRUE; else v=FALSE;
  984.              if(id==3)
  985.               {
  986.                bool=MultiRequest("Wollen Sie den Datenträger auf",
  987.                                  "Fehler überprüfen ?",
  988.                                  "Ja, Prüfen","Nein, Zurück");
  989.               }
  990.              else
  991.               {
  992.                bool=MultiRequest("Hard-Format: Alle Daten werden gelöscht!",
  993.                                  "Sind Sie wirklich sicher ?",
  994.                                  "Ja, Format","NEIN! Zurück");
  995.               }
  996.              if(bool==TRUE)
  997.               {
  998.                MotorCNT[num]=5;
  999.                BytesPerTrack=ud[num].SectorsPerTrack*ud[num].Heads*512;
  1000.                FormatMemory=AllocMem(BytesPerTrack,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1001.                if(FormatMemory!=NULL)
  1002.                 {
  1003.                  SetDrMd(rp,JAM2);
  1004.                  j=0;
  1005.                  for(Track=0;Track<ud[num].Tracks;Track++)
  1006.                   {
  1007.                    sprintf(&text,"   %ld   ",Track);
  1008.                    DrawNTextBorder(win,190,30,100,12,&text);
  1009.                    sprintf(&text,"   %3ld %%   ",((Track*100)/(ud[num].Tracks-1)));
  1010.                    DrawNTextBorder(win,190,44,100,12,&text);
  1011.                    if(ud[num].File==FALSE)
  1012.                     {
  1013.                      if(id==3)
  1014.                       {
  1015.                        td[num].Request->io_Data=FormatMemory;
  1016.                        td[num].Request->io_Length=BytesPerTrack;
  1017.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1018.                        td[num].Request->io_Command=CMD_READ;
  1019.                        i=DoIO(td[num].Request);
  1020.                        if(i!=0)
  1021.                         {
  1022.                          if(i==29)
  1023.                           {
  1024.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1025.                            Track=ud[num].Tracks;
  1026.                           }
  1027.                          else
  1028.                           {
  1029.                            sprintf(&text,"Fehler #%ld auf Track %ld.",i,Track);
  1030.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1031.                           }
  1032.                          j++;
  1033.                         }
  1034.                       }
  1035.                      else
  1036.                       {
  1037.                        td[num].Request->io_Data=FormatMemory;
  1038.                        td[num].Request->io_Length=BytesPerTrack;
  1039.                        td[num].Request->io_Offset=Track*BytesPerTrack;
  1040.                        td[num].Request->io_Command=TD_FORMAT;
  1041.                        i=DoIO(td[num].Request);
  1042.                        if(i!=0)
  1043.                         {
  1044.                          sprintf(&text,"Format: Fehler #%ld auf Track %ld.",i,Track);
  1045.                          DrawCNTextBorder(win,10,58,280,12,&text);
  1046.                          j++;
  1047.                          if(i==28)
  1048.                           {
  1049.                            InfoRequest("Das Medium ist schreibgeschützt.");
  1050.                            Track=ud[num].Tracks;
  1051.                           }
  1052.                          else if(i==29)
  1053.                           {
  1054.                            InfoRequest("Das Medium ist nicht eingelegt.");
  1055.                            Track=ud[num].Tracks;
  1056.                           }
  1057.                         }
  1058.                        if((v==TRUE)&&(Track<ud[num].Tracks))
  1059.                         {
  1060.                          td[num].Request->io_Data=FormatMemory;
  1061.                          td[num].Request->io_Length=BytesPerTrack;
  1062.                          td[num].Request->io_Offset=Track*BytesPerTrack;
  1063.                          td[num].Request->io_Command=CMD_READ;
  1064.                          i=DoIO(td[num].Request);
  1065.                          if(i!=0)
  1066.                           {
  1067.                            sprintf(&text,"Verify: Fehler #%ld auf Track %ld.",i,Track);
  1068.                            DrawCNTextBorder(win,10,58,280,12,&text);
  1069.                            j++;
  1070.                           }
  1071.                         }
  1072.                       }
  1073.                     }
  1074.                   }
  1075.                  if(j==0)
  1076.                   {
  1077.                    if(id==3) InfoRequest("Der Datenträger ist fehlerfrei.");
  1078.                   }
  1079.                  else
  1080.                   {
  1081.                    if(id==3)
  1082.                     {
  1083.                      sprintf(&text,"%ld Fehler gefunden worden.",j);
  1084.                      MultiRequest("Bei der Überprüfung sind",&text,"Okay",NULL);
  1085.                     }
  1086.                    else
  1087.                     {
  1088.                      sprintf(&text,"%ld Fehler aufgetreten.",j);
  1089.                      MultiRequest("Bei der Formatierung sind",&text,"Okay",NULL);
  1090.                     }
  1091.                   }
  1092.                  FreeMem(FormatMemory,BytesPerTrack);
  1093.                 }
  1094.               }
  1095.             break;
  1096.            case 1:
  1097.              ende=TRUE;
  1098.             break;
  1099.           }
  1100.         break;
  1101.        case CLOSEWINDOW:
  1102.          ende=TRUE;
  1103.         break;
  1104.       }
  1105.     }
  1106.    DeleteStdWindow(win);
  1107.   }
  1108. }
  1109.  
  1110.  
  1111. /* FAT berechnen */
  1112. VOID CalcFAT(num)
  1113.  UWORD num;
  1114. {
  1115.  REGISTER UWORD anz,i;
  1116.  REGISTER ULONG bytes,plus,sek,spc;
  1117.  
  1118.  
  1119.  sek=ud[num].Tracks*ud[num].Heads*ud[num].SectorsPerTrack;
  1120.  if(sek>4096)
  1121.   {
  1122.    bytes=sek*2;       /* FAT 16-Bit */
  1123.   }
  1124.  else
  1125.   {
  1126.    bytes=(sek*3)/2;   /* FAT 12-Bit */
  1127.   }
  1128.  plus=0;
  1129.  anz=0;
  1130.  for(i=0;i<32000;i++)
  1131.   {
  1132.    if(plus>=bytes)
  1133.     {
  1134.      spc=1;
  1135.      if(anz>15)
  1136.       {
  1137.        do
  1138.         {
  1139.          spc=spc*2;
  1140.          anz=anz/2;
  1141.         } while(anz>15);
  1142.       }
  1143.      jhword->Arg5=anz;
  1144.      jhbyte->Arg6=spc;
  1145.      return;
  1146.     }
  1147.    else
  1148.     {
  1149.      plus+=512;
  1150.      anz++;
  1151.     }
  1152.   }
  1153. }
  1154.  
  1155.  
  1156. /* File-Laufwerk bearbeiten */
  1157. VOID BearbeiteFile(num)
  1158.  UWORD num;
  1159. {
  1160.  UBYTE                       text[35];
  1161.  REGISTER BOOL               bool;
  1162.  REGISTER UBYTE             *mem;
  1163.  REGISTER ULONG              i,j,k,l;
  1164.  register struct FileHandle *fh;
  1165.  register struct Window     *win;
  1166.  register struct RastPort   *rp;
  1167.  struct TextFont            *opal;
  1168.  struct IntuiMessage        *msg;
  1169.  
  1170.  if(td[num].Valid==FALSE)
  1171.   {
  1172.    bool=MultiRequest("Es existiert keine Laufwerksdatei.",
  1173.                      "Möchten Sie eine erstellen ?",
  1174.                      "Ja, Erstellen","Nein, Zurück");
  1175.    if(bool==TRUE)
  1176.     {
  1177.      j=512*ud[num].SectorsPerTrack*ud[num].Heads;
  1178.      mem=AllocMem(j,MEMF_CLEAR|MEMF_PUBLIC);
  1179.      if(mem!=NULL)
  1180.       {
  1181.        fh=Open(&ud[num].Name,MODE_NEWFILE);
  1182.        if(fh!=NULL)
  1183.         {
  1184.          win=CreateStdWindow("Laufwerksdatei erstellen",
  1185.                              75,90,300,30,GADGETUP|CLOSEWINDOW,
  1186.                              WINDOWCLOSE|WINDOWDEPTH|ACTIVATE|WINDOWDRAG);
  1187.          if(win!=NULL)
  1188.           {
  1189.            opal=GetOpalFont();
  1190.            rp=win->RPort;
  1191.            SetFont(rp,opal);
  1192.            CreateBoolGadget(win,10,15,120,12,"Stop !",1);
  1193.            bool=FALSE;
  1194.            if(win!=NULL)
  1195.             {
  1196.              for(i=0;i<ud[num].Tracks;i++)
  1197.               {
  1198.                sprintf(&text,"Track %ld von %ld",i,ud[num].Tracks);
  1199.                DrawCNTextBorder(win,140,15,150,12,&text);
  1200.                k=Write(fh,mem,j);
  1201.                if(k!=j)
  1202.                 {
  1203.                  InfoRequest("Schreibfehler!");
  1204.                  i=ud[num].Tracks;
  1205.                  bool=TRUE;
  1206.                 }
  1207.                msg=GetMsg(win->UserPort);
  1208.                if(msg!=NULL)
  1209.                 {
  1210.                  InfoRequest("Stop!");
  1211.                  i=ud[num].Tracks;
  1212.                  bool=TRUE;
  1213.                 }
  1214.               }
  1215.              if(bool==FALSE)
  1216.               {
  1217.                td[num].FileHandle=fh;
  1218.                td[num].Valid=TRUE;
  1219.               }
  1220.              else
  1221.               {
  1222.                Close(fh);
  1223.                DeleteFile(&ud[num].Name);
  1224.               }
  1225.             }
  1226.            DeleteStdWindow(win);
  1227.           }
  1228.          else
  1229.           {
  1230.            Close(fh);
  1231.            DeleteFile(&ud[num].Name);
  1232.            ErrorRequest(ERROR_ALLOC);
  1233.           }
  1234.         }
  1235.        else InfoRequest("Laufwerksdatei läßt sich nicht erstellen.");
  1236.        FreeMem(mem,j);
  1237.       }
  1238.      else ErrorRequest(ERROR_ALLOC);
  1239.     }
  1240.   }
  1241.  else
  1242.   {
  1243.    win=CreateStdWindow("Laufwerksdatei-Information",75,90,300,90,
  1244.                        CLOSEWINDOW|GADGETUP,
  1245.                        WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  1246.    if(win!=NULL)
  1247.     {
  1248.      opal=GetOpalFont();
  1249.      rp=win->RPort;
  1250.      SetFont(rp,opal);
  1251.      CreateBoolGadget(win,10,15,120,12,"Okay",1);
  1252.  
  1253.      sprintf(&text,"Spuren: %ld",ud[num].Tracks);
  1254.      DrawNTextBorder(win,10,30,280,12,&text);
  1255.      sprintf(&text,"S/L-Köpfe: %ld",ud[num].Heads);
  1256.      DrawNTextBorder(win,10,45,280,12,&text);
  1257.      sprintf(&text,"Sektoren/Spur: %ld",ud[num].SectorsPerTrack);
  1258.      DrawNTextBorder(win,10,60,280,12,&text);
  1259.      sprintf(&text,"KBytes: %ld",(ud[num].Tracks*ud[num].SectorsPerTrack*ud[num].Heads)/2);
  1260.      DrawNTextBorder(win,10,75,280,12,&text);
  1261.  
  1262.      WaitPort(win->UserPort);
  1263.      DeleteStdWindow(win);
  1264.     }
  1265.   }
  1266. }
  1267.  
  1268.  
  1269. /* Motor-Kontrollprozeß */
  1270. VOID Motor()
  1271. {
  1272.  register struct Message *msg;
  1273.  
  1274.  geta4();
  1275.  do
  1276.   {
  1277.    Delay(50);
  1278.    Signal(MainTask,TaskSignalMask);
  1279.    msg=GetMsg(TaskPort);
  1280.   }
  1281.  while(msg==NULL);
  1282.  DeletePort(TaskPort);
  1283.  ReplyMsg(msg);
  1284.  Exit(0);
  1285. }
  1286.  
  1287.  
  1288. /* Motor ein- und ausschalten */
  1289. VOID MotorOnOff(num,status)
  1290.  UWORD num;
  1291.  UWORD status;
  1292. {
  1293.  
  1294.  if(td[num].Valid==TRUE)
  1295.   {
  1296.    if(ud[num].File==FALSE)
  1297.     {
  1298.      td[num].Request->io_Command=TD_MOTOR;
  1299.      td[num].Request->io_Length=status;
  1300.      SendIO(td[num].Request);
  1301.     }
  1302.   }
  1303. }
  1304.  
  1305.  
  1306. /* Datenträger formatieren */
  1307. VOID Format()
  1308. {
  1309.  REGISTER ULONG  tSize;
  1310.  REGISTER UBYTE *fBuffer;
  1311.  REGISTER UWORD  res,i;
  1312.  
  1313.  res=0;
  1314.  if(ud[Active].File==FALSE)
  1315.   {
  1316.    tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1317.    fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1318.    if(fBuffer!=NULL)
  1319.     {
  1320.      td[Active].Request->io_Data=fBuffer;
  1321.      td[Active].Request->io_Length=tSize;
  1322.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1323.      td[Active].Request->io_Command=TD_FORMAT;
  1324.      i=DoIO(td[Active].Request);
  1325.      if(i==0)
  1326.       {
  1327.        if(jhword->Arg3==1)
  1328.         {
  1329.          td[Active].Request->io_Command=CMD_READ;
  1330.          i=DoIO(td[Active].Request);
  1331.          if(i!=0) res=3;
  1332.         }
  1333.       } else res=2;
  1334.      MotorCNT[Active]=ud[Active].Motor;
  1335.      FreeMem(fBuffer,tSize);
  1336.     }
  1337.    else res=1;
  1338.   }
  1339.  jhword->Arg2=res;
  1340. }
  1341.  
  1342.  
  1343. /* Datenträger kopieren */
  1344. VOID Kopiere()
  1345. {
  1346.  REGISTER ULONG  tSize;
  1347.  REGISTER UBYTE *fBuffer;
  1348.  REGISTER UWORD  res,i;
  1349.  
  1350.  res=0;
  1351.  tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
  1352.  fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
  1353.  if(fBuffer!=NULL)
  1354.   {
  1355.    if(ud[Active].File==FALSE)
  1356.     {
  1357.      td[Active].Request->io_Data=fBuffer;
  1358.      td[Active].Request->io_Length=tSize;
  1359.      td[Active].Request->io_Offset=jhword->Arg2*tSize;
  1360.      td[Active].Request->io_Command=CMD_READ;
  1361.      i=DoIO(td[Active].Request);
  1362.     }
  1363.    else
  1364.     {
  1365.      Seek(td[Active].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1366.      i=Read(td[Active].FileHandle,fBuffer,tSize);
  1367.      if(i!=tSize) i=1; else i=0;
  1368.     }
  1369.    if(i==0)
  1370.     {
  1371.      if(ud[jhword->Arg3].File==FALSE)
  1372.       {
  1373.        td[jhword->Arg3].Request->io_Data=fBuffer;
  1374.        td[jhword->Arg3].Request->io_Length=tSize;
  1375.        td[jhword->Arg3].Request->io_Offset=jhword->Arg2*tSize;
  1376.        td[jhword->Arg3].Request->io_Command=TD_FORMAT;
  1377.        i=DoIO(td[jhword->Arg3].Request);
  1378.        if(i==0)
  1379.         {
  1380.          if(jhword->Arg4==1)
  1381.           {
  1382.            td[jhword->Arg3].Request->io_Command=CMD_READ;
  1383.            i=DoIO(td[jhword->Arg3].Request);
  1384.            if(i!=0) res=4;
  1385.           }
  1386.         } else res=3;
  1387.       }
  1388.      else
  1389.       {
  1390.        Seek(td[jhword->Arg3].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
  1391.        i=Write(td[jhword->Arg3].FileHandle,fBuffer,tSize);
  1392.        if(i!=tSize) res=3;
  1393.       }
  1394.     } else res=2;
  1395.    MotorCNT[Active]=ud[Active].Motor;
  1396.    MotorCNT[jhword->Arg3]=ud[jhword->Arg3].Motor;
  1397.    FreeMem(fBuffer,tSize);
  1398.   } else res=1;
  1399.  jhword->Arg2=res;
  1400. }
  1401.  
  1402.  
  1403. /* Information */
  1404. VOID ShowInfo()
  1405. {
  1406.  InformationBox("ATUtilities Disk Transfer - Information",
  1407.                 "$VER: Disk Transfer - Version 4.0",
  1408.                 "Copyright (C) 1993 by",
  1409.                 "Thomas Dreibholz",
  1410.                 "All rights reserved.",
  1411.                 "AT:Icons/Utility");
  1412. }
  1413.  
  1414.  
  1415. #ifdef SHAREWARE
  1416. VOID RegCheck()
  1417. {
  1418.  REGISTER BOOL               bool;
  1419.  REGISTER UWORD              i,j;
  1420.  register struct TextFont   *opal;
  1421.  register struct FileHandle *fh;
  1422.  register struct RastPort   *rp;
  1423.  register struct Window     *RegWindow;
  1424.  
  1425.  bool=FALSE;
  1426.  fh=Open("SYS:PC/ATUtilities/ATUtilities.reg",MODE_OLDFILE);
  1427.  if(fh!=NULL)
  1428.   {
  1429.    Read(fh,&Kunde,sizeof(struct Kunde));
  1430.    Close(fh);
  1431.    i=CHECKSTR(&Kunde.Code,&Kunde.Vorname,CODE_VN,VN1);
  1432.    i+=CHECKSTR(&Kunde.Code,&Kunde.Nachname,CODE_NN,NN1);
  1433.    i+=CHECKSTR(&Kunde.Code,&Kunde.Straße,CODE_ST,ST1);
  1434.    i+=CHECKSTR(&Kunde.Code,&Kunde.Land,CODE_LA,LA1);
  1435.    i+=CHECKSTR(&Kunde.Code,&Kunde.Postleitzahl,CODE_PL,PL1);
  1436.    i+=CHECKSTR(&Kunde.Code,&Kunde.Ort,CODE_OR,OR1);
  1437.    i+=CHECKCODE(&Kunde.Code);
  1438.    if(i==0)
  1439.     {
  1440.      j=GETPRG(Kunde.Code);
  1441.      if(j & PROG_DISKTRANSFER) bool=TRUE;
  1442.     }
  1443.   }
  1444.  if(bool==FALSE)
  1445.   {
  1446.    RegWindow=CreateStdWindow(NULL,75,100,450,72,0L,0L);
  1447.    if(RegWindow!=NULL)
  1448.     {
  1449.      rp=RegWindow->RPort;
  1450.      opal=GetOpalFont();
  1451.      SetFont(rp,opal);
  1452.      SelectStdFPen(rp);
  1453.      WriteText(rp,15,10,"Disk Transfer - Unregistrierte Version");
  1454.      WriteText(rp,15,23,"Dieses Programm ist Shareware! Möchten Sie es");
  1455.      WriteText(rp,15,33,"regelmäßig nutzen, so müssen Sie es registrieren");
  1456.      WriteText(rp,15,43,"lassen! Weitere Informationen dazu finden Sie in");
  1457.      WriteText(rp,15,53,"der Datei \"Registrierung.DOK\" und im Hilfe-");
  1458.      WriteText(rp,15,63,"system unter \"Shareware-Registrierung\".");
  1459.      Delay(500);
  1460.      DeleteStdWindow(RegWindow);
  1461.     }
  1462.   }
  1463. }
  1464. #endif
  1465.  
  1466.  
  1467. BOOL AddCache(block,offset,len)
  1468.  UBYTE *block;
  1469.  ULONG  offset;
  1470.  UWORD  len;
  1471. {
  1472.  REGISTER UBYTE             *copy;
  1473.  register struct CacheBlock *cb,*old;
  1474.  
  1475.  if(td[Active].FirstCacheBlock==NULL)
  1476.   {
  1477.    td[Active].Request->io_Command=TD_PROTSTATUS;
  1478.    DoIO(td[Active].Request);
  1479.    if(td[Active].Request->io_Actual!=0) return(FALSE);
  1480.  
  1481.  
  1482. /*   td[Active].Request->io_Command=TD_CHANGENUM;
  1483.    DoIO(td[Active].Request);
  1484.    if(td[Active].Request->io_Actual!=td[Active].Changes) return(FALSE);
  1485. */
  1486.  
  1487.  
  1488.   }
  1489.  
  1490.  cb=AllocRemember(&td[Active].CacheRemember,sizeof(struct CacheBlock),MEMF_PUBLIC|MEMF_CLEAR);
  1491.  if(cb==NULL) return(FALSE);
  1492.  copy=AllocRemember(&td[Active].CacheRemember,len,MEMF_PUBLIC);
  1493.  if(copy==NULL) return(FALSE);
  1494.  
  1495.  cb->Offset=offset;
  1496.  cb->Length=len;
  1497.  cb->Memory=copy;
  1498.  cb->Changes=td[Active].Changes;
  1499.  CopyMemQuick(block,copy,len);
  1500.  if(td[Active].FirstCacheBlock==NULL)
  1501.    td[Active].FirstCacheBlock=cb;
  1502.  else
  1503.   {
  1504.    old=td[Active].FirstCacheBlock;
  1505.    if(old->NextCacheBlock!=NULL)
  1506.     {
  1507.      while(old->NextCacheBlock!=NULL)
  1508.       old=old->NextCacheBlock;
  1509.     }
  1510.    old->NextCacheBlock=cb;
  1511.   }
  1512.  
  1513.  MotorCNT[Active]=ud[Active].Motor;
  1514.  if(MotorCNT[Active]==0) MotorCNT[Active]=5;
  1515.  MotorOnOff(Active,1);
  1516.  jhword->Arg2=0;
  1517.  return(TRUE);
  1518. }
  1519.  
  1520.  
  1521. VOID WriteCache(ii)
  1522.  UWORD ii;
  1523. {
  1524.  register struct CacheBlock *cb;
  1525.  
  1526.  if(td[ii].FirstCacheBlock!=NULL)
  1527.   {
  1528.    cb=td[ii].FirstCacheBlock;
  1529.    do
  1530.     {
  1531. /*     if(cb->Changes==td[ii].Changes)
  1532.       { */
  1533.        CopyMemQuick(cb->Memory,mem,cb->Length);
  1534.        td[ii].Request->io_Data=mem;
  1535.        td[ii].Request->io_Offset=cb->Offset;
  1536.        td[ii].Request->io_Length=cb->Length;
  1537.        td[ii].Request->io_Command=CMD_WRITE;
  1538.        DoIO(td[ii].Request);
  1539.     /*  } */
  1540.      cb=cb->NextCacheBlock;
  1541.     } while(cb!=NULL);
  1542.  
  1543.    td[ii].Request->io_Command=CMD_UPDATE;
  1544.    DoIO(td[ii].Request);
  1545.    FreeRemember(&td[ii].CacheRemember,TRUE);
  1546.    td[ii].CacheRemember=NULL;
  1547.    td[ii].FirstCacheBlock=NULL;
  1548.   }
  1549. }
  1550.  
  1551.